package cn.marinda.resturants.controller;

import cn.marinda.resturants.entity.Orders;
import cn.marinda.resturants.entity.Staff;
import cn.marinda.resturants.enums.EntityJson;
import cn.marinda.resturants.global.Pages;
import cn.marinda.resturants.service.StaffService;
import cn.marinda.resturants.utils.ApiResult;
import cn.marinda.resturants.utils.IOUtils;
import cn.marinda.resturants.utils.PagesResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/** 员工控制器
 *
 * @date 2021/12/2
 * @version 1.0
 * @author Marinda
 *
 */
@RestController
@RequestMapping("/staff")
public class StaffController {

    @Resource
    private StaffService staffService;




    @RequestMapping("/queryList")
    private ApiResult queryList(){

        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,staffService.queryList());
    }

    @RequestMapping("/index")
    private ApiResult selectUid(@RequestParam("uid") String uid){
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE, Arrays.asList(staffService.selectByUid(uid)));
    }

    /**
     * 添加一个用户
     *
     * @param staff 新用户
     * @return 结果
     */
    @RequestMapping("/add")
    public ApiResult addStaff(Staff staff) {
        return staffService.addStaff(staff) ?  new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,null) :  new ApiResult(ApiResult.ON_FAIL,ApiResult.FAIL_MESSAGE,null);

    }


    /** 列表分页
     *
     * @date 2021/12/1
     * @return 结果
     */
    @RequestMapping("/pages")
    private PagesResult selectPages(@RequestParam("page") int page, @RequestParam("limit") int limit)
    {
        IPage<Staff> staffIPage = staffService.selectStaffPage(new Pages<>(page,limit));
        return new PagesResult(0,staffIPage.getRecords(),(int)staffIPage.getTotal(),staffIPage.getSize());
    }

    /**
     * 删除一个员工
     *
     * @param uid uid
     * @return 结果
     */
    @RequestMapping("/delete")
    public ApiResult deleteStaff(String uid) {
        return staffService.deleteStaff(uid) ?  new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,null) :  new ApiResult(ApiResult.ON_FAIL,ApiResult.FAIL_MESSAGE,null);

    }

    /**
     * 修改一个员工
     *
     * @param staff 员工
     * @return 结果
     */
    @RequestMapping("/update")
    public  ApiResult updateStaff(Staff staff) {
        return staffService.updateStaff(staff) ?  new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,null) :  new ApiResult(ApiResult.ON_FAIL,ApiResult.FAIL_MESSAGE,null);

    }

    /**
     * 模糊查询一批名称的
     *
     * @param likeName 模糊名称
     * @return 列表
     */
    @RequestMapping("/likeName")
    public ApiResult selectNameLike(String likeName) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,staffService.selectNameLike(likeName));

    }

    /**
     * 员工加入日期区间列表
     *
     * @param startDate 开始日期
     * @param endDate   结束日期
     * @return 列表
     */
    @RequestMapping("/joinData")
    public ApiResult selectJoinDateInterval(String startDate, String endDate) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,staffService.selectJoinDateInterval(startDate, endDate));

    }

    /**
     * 根据性别区间拿到员工 列表
     *
     * @param sex 性别
     * @return 员工列表
     */
    @RequestMapping("/sex")
    public ApiResult selectSexInterval(char sex) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,staffService.selectSexInterval(sex));

    }

    /**
     * 员工部门列表
     *
     * @param department 部门列表
     * @return 员工列表
     */
    @RequestMapping("/department")
    public ApiResult selectDepartment(String department) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,staffService.selectDepartment(department));
    }

    /**
     * 查询手机号指定的员工
     *
     * @param phone 手机号
     * @return 员工
     */
    @RequestMapping("/phone")
    public ApiResult selectPhone(long phone) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,staffService.selectPhone(phone));
    }

    /**
     * 查询邮箱指定返回的员工
     *
     * @param email 邮箱
     * @return 员工
     */
    @RequestMapping("/email")
    public ApiResult selectEmail(String email) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,staffService.selectEmail(email));

    }

    /**
     * 查询员工工资号
     *
     * @param uid 员工id
     * @return 员工工资号
     */
    @RequestMapping("/salary")
    public ApiResult selectSalaryUid(String uid) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,staffService.selectSalaryUid(uid));

    }

}
